<template>
    <div style="padding: 26px; background-color: white; font-size: 13px">
      <div>
        <span class="title">工单列表</span>
      </div>
      <div class="operation">
        <span>状态：</span>
        <el-select v-model="status" placeholder="请选择" size="small" class="input_right">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>

        <span>优先级：</span>
        <el-select v-model="priority" placeholder="请选择" size="small" class="input_right">
          <el-option
            v-for="item in priorityOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>

        <el-input
          class="search"
          placeholder="标题或内容"
          size="small"
          style="width: 240px"
          @keyup.enter.native="search"
          v-model="keyWord">
          <i class="el-icon-search" slot="append" style="cursor: pointer;" @click="search"></i>
        </el-input>

      </div>

      <el-table
        :data="tableData"
        :cell-style="isClose"
        style="width: 100%">
        <el-table-column
          prop="orderNo"
          label="编号">
        </el-table-column>
        <el-table-column
          prop="title"
          label="标题">
          <template slot-scope="scope">
            <span @click="rowClick(scope.row)" class="feedbakc_title">{{scope.row.title}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="orderType"
          label="类型">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          width="180">
        </el-table-column>
        <el-table-column
          width="80"
          label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.orderStatus == 0" style="color:#2A97F9">未受理</span>
            <span v-if="scope.row.orderStatus == 1">受理中</span>
            <span v-if="scope.row.orderStatus == 2">已关闭</span>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="优先级">
          <template slot-scope="scope">
            <span v-if="scope.row.orderLevel == '0'">普通</span>
            <span v-if="scope.row.orderLevel == '1'">紧急</span>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="操作">
          <template slot-scope="scope">

            <el-tooltip class="item" effect="dark" content="删除" placement="top" v-if="scope.row.orderStatus == 2">
              <span>
                <i class="icon-delete_icon" style="cursor: pointer"  @click.stop="beforDelete(scope.row.id)"></i>
              </span>
            </el-tooltip>
            <i class="icon-delete_icon" style="color: #dddddd" v-else></i>
          </template>
        </el-table-column>

        <div slot="empty">
          <div>
            <img :src="empty" alt="" style="width: 250px" />
          </div>
        </div>

      </el-table>

      <el-dialog
        :visible.sync="dialogVisible"
        width="400px"
        center>
        <span slot="title" class="dialog-title">删除工单提醒</span>
        <div style="margin-top: 20px">
          <p style="text-align: center;font-weight: 600">您确定要删除这个工单吗？</p>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false" size="small">取 消</el-button>
          <el-button type="primary" @click="deleteFeedback" size="small">确 定</el-button>
        </span>
      </el-dialog>


      <el-pagination
        style="margin-top: 10px"
        align="right"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageNo"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageSize"
        layout="prev, pager, next, sizes"
        :total="total">
      </el-pagination>

    </div>
</template>

<script>
    import {myWorkOrder, deleteWorkOrder} from '@/api/feedback'
    export default {
        name: "index",
        data() {
            return{
                empty:'./img/empty.png',
                tableData: [],
                status: '-1', // 状态
                statusOptions: [
                    {
                        value: '0',
                        label: '未受理'
                    },
                    {
                        value: '1',
                        label: '受理中'
                    },
                    {
                        value: '2',
                        label: '已关闭'
                    },
                    {
                        value: '-1',
                        label: '全部'
                    }
                ], // 状态数组
                priority: "-1", // 优先级
                priorityOptions: [
                    {
                        value: '0',
                        label: '普通'
                    },
                    {
                        value: '1',
                        label: '紧急'
                    },
                    {
                        value: '-1',
                        label: '全部'
                    }
                ], // 优先级数组
                pageNo: 1,
                pageSize:10,
                keyWord: '',
                total:0,
                dialogVisible: false,
                deleteId: ''
            }
        },
        created() {
            this.init()
        },
        methods: {
          init() {
              myWorkOrder(this.pageNo, this.pageSize,this.keyWord, this.status, this.priority).then(res => {
                 if(res.data.success) {
                     this.tableData = res.data.data.records
                     this.total = res.data.data.total
                 }
              })
          },
            isClose({row}) {
              if(row.orderStatus == 2) {
                  return {
                      color: '#8C8C8C'
                  }
              }
            },
          rowClick(item) {
            console.log(item)
              this.$router.push(`/feedback/detail/${item.id}`)
          },
            handleSizeChange(size) {
              this.pageSize = size
              this.init()
            },
            handleCurrentChange(page) {
              this.pageNo = page
              this.init()
            },
            search() {
                this.pageNo = 1
                this.init()
            },
            beforDelete(id) { // 删除之前
              this.dialogVisible = true
              this.deleteId = id
            },
            deleteFeedback() { // 删除工单
                deleteWorkOrder(this.deleteId).then(res => {
                    if(res.data.success) {
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        })
                        this.dialogVisible = false
                        this.init()
                    }
                })
            }
        },
        watch: {
            status() {
                this.pageNo = 1
                this.init()
            },
            priority() {
                this.pageNo = 1
                this.init()
            }
        }
    }
</script>

<style scoped lang="scss">
.go_back{
  font-size: 25px !important;
  color: #2A97F9;
}
  .title{
    font-size: 18px;
    font-weight: 600;
    color: #435B77;
    margin-left: 10px;
  }
  .operation{
    padding: 20px;
    padding-left: 10px;
  }
  .input_right{
    margin-right: 10px;
  }
  .feedbakc_title{
    color: #2A97F9;
    cursor: pointer;
  }
</style>
